package com.marsrover.command;

import static com.marsrover.Directions.*;

import java.util.Arrays;
import java.util.List;

import com.marsrover.Location;

public abstract class ChangeDirectionCommand implements Command {
	private static final List<Character> CLOCKWISE_DIRECTIONS = Arrays.asList(NORTH, EAST, SOUTH, WEST);

	private Location location;

	public ChangeDirectionCommand(Location location) {
		this.location = location;
	}

	public void execute() {
		int currentDirectionIndex = CLOCKWISE_DIRECTIONS.indexOf(location.getDirection());
		int newDirectionIndex = (currentDirectionIndex + getNumbersOfTurn()) % 4;

		char newDirection = CLOCKWISE_DIRECTIONS.get(newDirectionIndex);
		location.setDirection(newDirection);
	}

	protected abstract int getNumbersOfTurn();
}
